<?php

	class PDataset
	{
		var $indexID;
		var $indexes;
		
		var $ids;
		
		function PDataset()
		{
			$this->indexID = true;
			$this->indexes = array();
			
			$this->ids = array();
		}
		
		
		function addElement(&$element)
		{
			// Add element in the elements array
			$this->elements[] = $element;
			
			// Index element by ID if set
			if ($this->indexID)
			{
				$id_field = $element->_model->id;
				$this->ids[$element->$id_field] = $element;
			}
			
			// Classify by other fields
			// Add in the future an option for several elements in one field
			foreach ($this->indexes as $index)
			{
				$this->elements[$index][$element->$index] = $element;
			}
		}
		
		// NECESARY TO FIX BEFORE USE
		private function paginate($epp)
		{
			$ref = $this->ds['fds'];
			
			if ($ref != null)
			{
				$n = count($ref);
				
				$npages = (int)($n / $this->epp) + 1;
				
				$ne = 0;
				
				for ($i = 1; $i <= $npages; $i++)
				{
					for ($j = 0; $j < $this->epp && $ne < $n; $j++)
					{
						$this->ds['pds'][$i][$j] = $ref[$ne];
						$ne++;
					}
				}
			}
		}
	}

?>
